from neo4j import GraphDatabase  # pip install neo4j-driver

NEO4J_CONFIG = {
    "uri": "bolt://127.0.0.1:7600",
    "auth": ("neo4j", "p1983njA1-ei"),
    "encrypted": False
}


def get_father(driver, xperson):
    with driver.session() as ss:

        cypher = 'match (p:Person{name: %r })<-[:Father]-(q:Person) return q.name' % xperson
        # 运行这条cypher语句
        record = ss.run(cypher)
        xname = None
        try:
            for xel in record:
                xname = xel[0]
                break
        except Exception as ex:
            print(ex)
        return xname


if '__main__' == __name__:
    driver = GraphDatabase.driver(**NEO4J_CONFIG)
    xperson = '金正恩'
    xname = get_father(driver, xperson)
    print(f'{xperson}的父亲是：{xname}')
